
(function () {
    var core = ecui,
        util = core.util,
        ui = ecui.ui,
        dom = ecui.dom;

    Object.assign(
        NS.data,
        {
        }
    );
    Object.assign(
        NS.ui,
        {

            /**
             * 操作按钮控件。
             * 筛选框动态的响应用户的输入并提供选择，用户不输入时 filter 表现与普通的输入框相同。
             * options 属性：
             * eType   业务类型，1：合同；2：订单；3：结算单；4：厂牌结算单 5：艺人详情；6：出库单；7：单据；8：厂牌项目
             * cType   操作类型，-1：删除，0：撤销，1：提交，2：驳回，3：通过，4：中止
             * tip     操作玩提示信息
             * @control
             */
            ApprovalSubmitBtn: core.inherits(
                ui.Button,
                function (el, options) {
                    ui.Button.call(this, el, options);
                    this._sOptId = options.optId;
                    this._sEType = options.eType;
                    this._sCType = options.cType;
                    this._sTip = options.tip;
                },
                {
                    onkeydown: function (event) {
                        if (event.which === 13) {
                            this.getInput().blur();
                            ecui.dispatchEvent(this, 'blur');
                            ecui.dispatchEvent(this, 'submit');
                        }
                    },
                    onclick: function (event) {
                        ecui.dispatchEvent(this, 'submit');
                        event.stopPropagation();
                    },
                    onsubmit: function () {
                        if (this._bRequest) {
                            return;
                        }
                        var text = ['', '', '拒绝', '同意']; // 0-撤销 1-提交 2-驳回 3-通过 4-中止
                        var urlMap = [
                            '',
                            '/erp-management/contract/action',
                            '/erp-management/venue/order/action',
                            '/erp-management/finance/play/income/action',
                            '/erp-management/sponsor/finance/play/income/action',
                            '/erp-management/artist/action',
                            '/erp-management/artist/stock/action',
                            '/erp-management/audit/operate',
                            '/erp-management/audit/operate'
                        ];
    
                        this._bRequest = true;
                        ecui.confirm(
                            '是否' + text[this._sCType],
                            function () {
                                ecui.esr.request(
                                    util.stringFormat('data@JSON {0}?id={1}&action={2}', urlMap[this._sEType], this._sOptId, this._sCType),
                                    function () {
                                        this._bRequest = false;
                                        var data = ecui.esr.getData('data');
                                        if (data instanceof Object) {
                                            ecui.tip('warn', this._sTip);
                                            var item = this.getParent();
                                            item.getParent().remove(item);
                                        }
                                    }.bind(this),
                                    function () {
                                        this._bRequest = false;
                                        return false;
                                    }.bind(this)
                                );
                            }.bind(this),
                            function () {
                                this._bRequest = false;
                            }.bind(this)
                        );
                    }
                }
            )
        }
    );
    ecui.esr.addRoute('quickList', {
        model: [''],
        weight: 1,
        frame: true,
        onbeforerequest: function (context) {
            context.num = mao.util.getTimeRandom();
        },
        onbeforerender: function (context) {
        },
        onafterrender: function (context) {
        }
    });
}());

